﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Splittergame.Model;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

namespace Splittergame
{
    class BallView
    {
        Texture2D ballTexture;
        Texture2D ram;
        Texture2D crossHair;
        SoundEffect fireSound;
        SoundEffectInstance fireSoundInstance;
        Ballsimulation m_ballSimulation;
        Vector2 crossHairPosition;
        Vector2 ramVisual;

        public BallView(Ballsimulation ballSimulation)
        {
            m_ballSimulation = ballSimulation;
        }

        public void LoadContent(ContentManager Content)
        {
            crossHair = Content.Load<Texture2D>("crosshair");
            ballTexture = Content.Load<Texture2D>("juggeboll");
            ram = Content.Load<Texture2D>("ram");
            fireSound = Content.Load<SoundEffect>("fire");

            fireSoundInstance = fireSound.CreateInstance();
        }

        public void Draw(SpriteBatch spritebatch, Camera camera)
        {

            Vector2 ramPosition = new Vector2(0.0f, 0.0f);
            int offsetX = camera.GetOffsetX();
            int offsetY = camera.GetOffsetY();

            //Rectangle newRamRect = camera.getRamRectangle(ramPosition);
            //newRamRect.Offset(offsetX, offsetY);
            //ramVisual = camera.GetVisual(ramPosition);
            //spritebatch.Draw(ram, newRamRect, Color.White);

            //Rectangle crossHairRect = camera.getVisualRect(m_ballSimulation.m_mouseState.X, m_ballSimulation.m_mouseState.Y, 0.5f);
            //spriteBatch.Draw(smokeTexture, positionVector, null, color, rotation, origin, size, SpriteEffects.None, 0);
            crossHairPosition = new Vector2(m_ballSimulation.m_mouseState.X, m_ballSimulation.m_mouseState.Y);
            Rectangle crossHairRect = new Rectangle((int)crossHairPosition.X, (int)crossHairPosition.Y, 100, 100);
            spritebatch.Draw(crossHair, crossHairRect, null, Color.White, 0, new Vector2(crossHair.Width/2, crossHair.Height/2), SpriteEffects.None, 0);

            foreach (Ball ball in m_ballSimulation.BallList)
            {
                float Ballsize = ball.ballRadius;
                Rectangle newBallRect = camera.getVisualRect(ball.getBallPosition().X, ball.getBallPosition().Y, ball.ballRadius);
                //newBallRect.Offset(offsetX, offsetY);
                spritebatch.Draw(ballTexture, newBallRect, Color.White);
            }

        }
        public Vector2 GetCrossHairPosition()
        {
            crossHairPosition.X = crossHairPosition.X / 10;
            crossHairPosition.Y = crossHairPosition.Y / 10;

            Console.WriteLine(crossHairPosition);
            return crossHairPosition;        
        }

        internal void MakeSound()
        {
            if (fireSoundInstance.State == SoundState.Stopped)
            {
                fireSoundInstance.Volume = 0.75f;
                fireSoundInstance.Play();
            }
        }
    }
}
